﻿using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using HKB.Web.DataHelper;
using HKB.Data;

public partial class Admin_Admin_navegate_link : Admin, IRequiresSessionState
{
    private new Conn conn = new Conn();
    private HL_NavegateBll _navegate = null;
    protected HL_NavegateBll m_navegate
    {
        get
        {
            if (this._navegate == null)
            {
                this._navegate = new HL_NavegateBll(this.conn);
            }
            return this._navegate;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.IsPostBack)
        {
            this.bind();
        }
    }
    protected void bind()
    {
        DataTable linksAll = this.m_navegate.GetLinksAll(new string[0]);
        this.gv_navegate.DataKeyNames = new string[]
		{
			"id"
		};
        this.gv_navegate.DataSource = linksAll;
        this.gv_navegate.DataBind();
    }
    protected void gv_navegate_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        this.gv_navegate.EditIndex = -1;
        this.bind();
    }
    protected void gv_navegate_RowEditing(object sender, GridViewEditEventArgs e)
    {
        this.gv_navegate.EditIndex = e.NewEditIndex;
        this.bind();
    }
    protected void gv_navegate_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            long id = Convert.ToInt64(this.gv_navegate.DataKeys[e.RowIndex].Value);
            string text = ((TextBox)this.gv_navegate.Rows[e.RowIndex].FindControl("txtTitle")).Text.ToString();
            string text2 = ((TextBox)this.gv_navegate.Rows[e.RowIndex].FindControl("txtLink")).Text.ToString();
            string text3 = ((TextBox)this.gv_navegate.Rows[e.RowIndex].FindControl("txtPosition")).Text;
            long num = Convert.ToInt64(((TextBox)this.gv_navegate.Rows[e.RowIndex].FindControl("txtOrderNumber")).Text);
            if (text == "" || text2 == "" || num <= 0L)
            {
                MessageBox.Show(this, "请填写完整信息！");
                e.Cancel = true;
            }
            bool flag = this.m_navegate.UpdateLink(id, text, text3, text2, num, "");
            if (flag)
            {
                base.Response.Write("修改成功");
            }
            else
            {
                MessageBox.Show(this, "修改失败！");
            }
        }
        catch (Exception)
        {
            MessageBox.Show(this, "请输入正确的内容！谢谢！");
            e.Cancel = true;
        }
        this.gv_navegate.EditIndex = -1;
        this.bind();
    }
    protected void btn_addLink_Click(object sender, EventArgs e)
    {
        try
        {
            string text = this.TextBoxTitle.Text.Trim();
            string text2 = this.TextBoxLink.Text.Trim();
            string position = this.TextBoxPosition.Text.Trim();
            long num = Convert.ToInt64(this.TextBoxOrderNumber.Text.Trim());
            if (text == "" || text2 == "" || num <= 0L)
            {
                MessageBox.Show(this, "请填写完整信息！");
            }
            else
            {
                bool flag = this.m_navegate.AddLink(text, position, text2, num, "添加的导航");
                if (flag)
                {
                    base.Response.Write("添加成功");
                }
                else
                {
                    MessageBox.Show(this, "添加失败！请查看是否有重复");
                }
            }
        }
        catch (Exception)
        {
            MessageBox.Show(this, "请输入正确的内容！谢谢！");
        }
        this.bind();
    }
    protected void gv_navegate_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            long id = Convert.ToInt64(this.gv_navegate.DataKeys[e.RowIndex].Value);
            bool flag = this.m_navegate.DeleteLink(id);
            if (flag)
            {
                MessageBox.Show(this, "删除成功");
                this.gv_navegate.EditIndex = -1;
                this.bind();
            }
            else
            {
                MessageBox.Show(this, "删除失败！");
            }
        }
        catch (Exception)
        {
            MessageBox.Show(this, "删除出错！");
            e.Cancel = true;
        }
    }
}
